<?php
try{
    session_start();
	//date_default_timezone_set("Asia/Ho_Chi_Minh");
    include '../../config.php';
	include '../classes/xl_crop_image.php';
	include '../classes/xl_logo_image.php';
    $dbh=new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME,DB_USER,DB_PASS);
    $dbh->exec('set names utf8');
	include '../../libraries/smarty/Smarty.class.php';
    include '../../libraries/send_gmail/send_gmail.php';
    include '../classes/xl_admin.php';
    $dt_xl_admin=new xl_admin;
	$dt_smarty=new Smarty;
    $dt_smarty->setTemplateDir('../templates/');
    $dt_smarty->setCompileDir('../templates_c/');
	include '../../libraries/function.php';
    function image($name_folder,$day){
        $dir="../../upload/$name_folder/$day";
        return $dir;
    }
    function debug($data){
        echo '<pre>';
        print_r($data);
        echo '</pre>';
        exit;
    }
    if(!isset($_SESSION['login'])){
        $_SESSION['last_url']=$_SERVER['REQUEST_URI'];
        header('Location: ../board/login.php');
        exit;
    }
    $read_position_admin=$dt_xl_admin->read();
    $url=$_SERVER['SCRIPT_NAME'];
    $arr=explode('/',$url);
    $n=count($arr);
    $file=$arr[$n-1];
    $file=str_replace('_sm.php','.php',$file);
    $folder=$arr[$n-2];
    $decentralization=$folder.'_'.$file;
    if($_SESSION['login']['email'] != $read_position_admin[1]['email']){
        $handling=$dt_xl_admin->handling_decentralization($_SESSION['login']['id'],$decentralization);
        if($handling === FALSE){
            throw new Exception('Bạn không có quyền truy câp ở '.$decentralization);
        }
    }
    $_SESSION['competence']='admin';
}catch(Exception $e){
    $dbh=NULL;
	$_SESSION['msg']=$e->getMessage();
	$_SESSION['type_msg']='error';
    if(empty($_SERVER['HTTP_REFERER'])){
        header('Location: ../statistics/index.php');
    } else {
         header('Location: '.$_SERVER['HTTP_REFERER']);
    }
    
   	
}